<template>
  <PageWrapper class="sys">
    <a-button type="primary" class="cqbtn" @click.stop="openPwd">重启网关</a-button>
    <BasicTable class="page-search-table" @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              tooltip: '编辑',
              onClick: openEdit.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <Dialog @register="registerModel" @success="submitSuccess" />
    <pwdDialog @register="registerPwd" @success="resetSuccess" ref="pwdDialog" />
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { useModal } from '/@/components/Modal';
  import { tableConfig } from './tableData';
  import Dialog from './dialog.vue';
  import pwdDialog from './pwdDialog.vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    components: {
      PageWrapper,
      BasicTable,
      Dialog,
      pwdDialog,
      TableAction,
    },
    setup(_) {
      const { createMessage } = useMessage();
      const [registerModel, { openModal: openModal }] = useModal();
      const [registerPwd, { openModal: openModalpwd }] = useModal();
      const [registerTable, { reload }] = useTable(tableConfig);
      const pwdDialog = ref(null);
      function submitSuccess(e) {
        reload();
        createMessage.success(e.isUpdate ? '修改成功' : '添加成功');
      }
      function resetSuccess() {
        createMessage.success('重启成功');
      }
      function openPwd() {
        pwdDialog.value.visible = true || null;
      }
      function openEdit(rowdata: Recordable) {
        openModal(true, {
          rowdata,
          isUpdate: true,
        });
      }
      return {
        registerModel,
        openModal,
        openModalpwd,
        registerTable,
        submitSuccess,
        resetSuccess,
        registerPwd,
        openEdit,
        openPwd,
        pwdDialog,
      };
    },
  });
</script>
<style lang="less" scoped>
  .sys {
    position: relative;
    .cqbtn {
      position: absolute;
      top: 12px;
      right: 25px;
    }
  }
</style>
